package com.atguigu.study.test;

import lombok.extern.slf4j.Slf4j;
import org.springframework.expression.EvaluationContext;
import org.springframework.expression.Expression;
import org.springframework.expression.spel.standard.SpelExpressionParser;
import org.springframework.expression.spel.support.StandardEvaluationContext;

@Slf4j
public class SpringElDemo {
    public static void main(String[] args){

        //1.日志占位符替换
        log.info("log:{}","abc");
        System.out.println();

        //2.String.format占位符替换
        String result = String.format("%,java","尚硅谷 study");
        System.out.println(result);
        System.out.println();

        //3.SpringElExpress表达式，#号后面的内容可以被具体内容替换
        String var = "#userid";
        SpelExpressionParser spelExpressionParser = new SpelExpressionParser();
        Expression expression = spelExpressionParser.parseExpression(var);

        EvaluationContext context = new StandardEvaluationContext();
        context.setVariable("userid","1234");

        String s = expression.getValue(context).toString();

        System.out.println(s);
    }
}
